package com.jerry.mingxing.ui.fashionrecommend;


import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.jerry.mingxing.R;
import com.jerry.mingxing.bean.LabelBean;
import com.jerry.mingxing.bean.NewBean;
import com.jerry.mingxing.ui.fashionnew.FashionNewAdapter;
import com.jerry.mingxing.ui.fashionnew.FashionNewContract;
import com.jerry.mingxing.ui.fashionnew.FashionNewPresenter;
import com.jerry.mingxing.widget.MyGridView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class FashionRecommendFragment extends Fragment implements FashionRecommendContract.View,FashionNewContract.View {
    @Bind(R.id.fashion_recommend_viewpager)
    ViewPager fashionRecommendViewpager;
    @Bind(R.id.fashion_recommend_gridview_label)
    GridView fashionRecommendGridviewLabel;
    @Bind(R.id.fashion_recommend_mgv)
    MyGridView fashionRecommendMgv;

    private View view;
    private Activity activity;
    private List<LabelBean.ResponseBean.DataBean.ItemsBean> totallist = new ArrayList<>();
    private FashionRecommendLabelAdapter fashionRecommendLabelAdapter;
    private FashionNewAdapter fashionNewAdapter;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_fashion_recommend, container, false);
        ButterKnife.bind(this, view);
        FashionRecommendPresenter presenter = new FashionRecommendPresenter(this);
        FashionNewPresenter fashionNewPresenter = new FashionNewPresenter(this);
        fashionNewPresenter.getData();
        presenter.getData();

        return view;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    @Override
    public void onResponse1(LabelBean label) {
        SetAadapter(label);

    }


    @Override
    public void onResponse(NewBean nbean) {
        fashionNewAdapter = new FashionNewAdapter(nbean.getResponse().getData().getItems(),getContext());
        fashionRecommendMgv.setAdapter(fashionNewAdapter);
    }

    @Override
    public void onFailure(String s) {

    }

    private void SetAadapter(LabelBean label) {
        totallist = label.getResponse().getData().getItems();
        fashionRecommendLabelAdapter = new FashionRecommendLabelAdapter(totallist, activity);
        fashionRecommendGridviewLabel.setAdapter(fashionRecommendLabelAdapter);


    }


}

